package com.databaseManager;

/**
 * @author addzero
 * @version 1.0
 * 排队单实体类
 */
public class QueueNumber {
    private long Qid;//排队号
    private String Pid;//病人身份证号，长度为18位的字符串
    private String EQTime;//排队时间，格式为yyyy-mm-dd hh:mm:ss
    private int PreFlag;//检测是否预约标志，0表示非预约用户，1表示预约用户
    private boolean isProQueue;//检测是否属于专家队列，true表示属于，false表示不属于
    private String DepNo;//科别编号，长度为7位
    private String DepName;//科别名
    private String Eid;//医生（专家）身份证号

    /**
     * QueueNumber类构造函数
     * @param qid 排队号
     * @param pid 病人身份证号，长度为18位的字符串
     * @param EQTime 排队时间，格式为yyyy-mm-dd hh:mm:ss
     */
    public QueueNumber(long qid, String pid, String EQTime) throws Exception {
        Qid = qid;
        Pid = pid;
        this.EQTime = EQTime;
        DatabaseFunc df = new DatabaseFunc();
        Order o = df.findOrder(Pid);
        if(o != null)
        {
            this.PreFlag = 1;
            if(o.getClass().getName().equals("com.databaseManager.ProOrder") )
            {
                this.isProQueue = true;
                this.DepName = ((ProOrder) o).getDepName();
                this.Eid = ((ProOrder) o).getEid();
                this.DepNo = df.findDepartment(this.DepName, SqlOP.GETDEPNO);
            }
            else if(o.getClass().getName().equals("com.databaseManager.DepOrder"))
            {
                this.isProQueue = false;
                this.DepName = ((DepOrder) o).getDepName();
                this.DepNo = ((DepOrder) o).getDepNo();
                this.Eid = null;
            }
        }
        else
        {
            this.PreFlag = 0;
            this.DepNo = df.findDepRegister(Pid);
            if(this.DepNo == null)
            {
                this.isProQueue = true;
                this.Eid = df.findProRegister(Pid);
                this.DepName = df.findDepartment(this.Eid, SqlOP.GETNAMEBYEID);
                this.DepNo = df.findDepartment(this.DepName, SqlOP.GETDEPNO);
            }
            else{
                this.isProQueue = false;
                this.DepName = df.findDepartment(this.DepNo, SqlOP.GETDEPNAME);
            }
        }
    }

    public QueueNumber(long qid, String pid, String EQTime, int preFlag, String depNo, String eid) throws Exception {
        Qid = qid;
        Pid = pid;
        this.EQTime = EQTime;
        PreFlag = preFlag;
        DatabaseFunc df = new DatabaseFunc();
        if(depNo == null)
        {
            this.isProQueue = true;
            Eid = eid;
            DepName = df.findDepartment(Eid, SqlOP.GETNAMEBYEID);
            DepNo = df.findDepartment(DepName, SqlOP.GETDEPNO);
        }
        else
        {
            this.isProQueue = false;
            DepNo = depNo;
            Eid = null;
            DepName = df.findDepartment(DepNo, SqlOP.GETDEPNAME);
        }
    }

    public long getQid() {
        return Qid;
    }

    public void setQid(long qid) {
        Qid = qid;
    }

    public String getPid() {
        return Pid;
    }

    public void setPid(String pid) {
        Pid = pid;
    }

    public String getEQTime() {
        return EQTime;
    }

    public void setEQTime(String EQTime) {
        this.EQTime = EQTime;
    }

    public int getPreFlag() {
        return PreFlag;
    }

    public void setPreFlag(int preFlag) {
        PreFlag = preFlag;
    }

    public boolean isProQueue() {
        return isProQueue;
    }

    public void setProQueue(boolean proQueue) {
        isProQueue = proQueue;
    }

    public String getDepNo() {
        return DepNo;
    }

    public void setDepNo(String depNo) {
        DepNo = depNo;
    }

    public String getDepName() {
        return DepName;
    }

    public void setDepName(String depName) {
        DepName = depName;
    }

    public String getEid() {
        return Eid;
    }

    public void setEid(String eid) {
        Eid = eid;
    }
}
